//我的界面中的用户信息
import { useEffect,useState } from 'react'
import Taro from "@tarojs/taro"
import { View,Image,Text} from '@tarojs/components'
import { JumpCard } from '../../components'
import './index.scss'
import avatar from '../../images/icon.png'
import {userDetailInfo} from '../../api/mode'


export default function MineHeader(){

  const [userInfo,setUserInfo]=useState({})

  useEffect(()=>{
    userDetailInfo(Taro.getStorageSync(`openid`)).then(res=>{
      // console.log(res.data.data);
      setUserInfo(res.data.data)})

  },[])

  const handleClick=()=>{
  if(!Taro.getStorageSync(`openid`)){
    Taro.showToast({
      title:'请先登录',
      icon:'error',
      duration:1500
    })}else{
      Taro.navigateTo({
        url: '/mine/pages/editorMyResume/editorMyResume'//跳转到编辑我的简历
      })
    }
  }


const getAge=()=>{
  let birthdayArr=userInfo.birthday.split('-')
  
  var timestamp = Date.parse(new Date());
  var date = new Date(timestamp);
  //获取年  
  var nowYear = date.getFullYear();
  // console.log(nowYear);
  return nowYear-birthdayArr[0]+'岁'
}

  return(
    <View className='MineHeader'>
      <View className='at-row'>
      <View className='at-col'>
      <View className='header'>
          <Image src={userInfo.photo?'data:image/png;base64,'+userInfo.photo:avatar} className='userAvatar' />
        </View>
      </View>
       <View className='at-col'>
       <View className='userInformation'>
            <Text style='display:block;font-size:larger' className='mineInfo'>{userInfo.name?userInfo.name:'姓名'}</Text>
            <Text style='display:block;color: #4D4D4D;' className='mineInfo'>{userInfo.type?userInfo.type:null}</Text>
            <Text style='display:block;color: #4D4D4D;' className='mineInfo'>{userInfo.birthday?getAge():'年龄'}</Text>
        </View>
       </View>
    </View>
    <View className='minejumpcard'>    <JumpCard  context='编辑信息' handleClick={handleClick} /></View>
    </View>
    
  )
}